﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using log4net;

namespace BSvr.Server
{
    class Program
    {
        private static ILog loger = log4net.LogManager.GetLogger(typeof(Program));

        private const string vers = "********************************************\n* 欢迎进入批处理服务器，当前版本号: V1.1.1 *\n********************************************\n";
        private const string tag = "bpserv> ";

        static void Main(string[] args)
        {
            Server server = new Server();
            System.Console.WriteLine("正在启动...");
            server.Init();
            server.Start();
            string cmd;
            System.Threading.Thread.Sleep(1000);
            System.Console.WriteLine("");
            System.Console.WriteLine(vers);
            
            System.Console.Write(tag);
            while ((cmd= System.Console.ReadLine()) != "exit")
            {
                string[] cmdargs = cmd.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                if (cmdargs.Length > 0)
                {
                    try
                    {
                        server.Excute(cmdargs);
                    }
                    catch (ArgumentNullException ae)
                    {
                        loger.Error(ae);
                        System.Console.WriteLine(ae.Message);
                    }
                    catch (ArgumentOutOfRangeException aoe) {
                        loger.Error(aoe);
                        System.Console.WriteLine(aoe.Message);
                    }
                }
                System.Console.Write(tag);
            }
            server.End();
        }
    }
}
